﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblItemImageDAO
    {
        private DBService _db = null;
        public TblItemImageDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        // lay hinh anh tuong ung voi id
        public TblItemImage GetItemImageByID(int ItemID, int ID)
        {

            TblItemImage image = new TblItemImage();
            try
            {
                DataTable dt = _db.ExeSP_DataTable("sp_TblItemImage_Lst",
                   new string[] { "@p_ItemID", "@Id" },
                   new object[] { ItemID, ID },
                  CommandType.StoredProcedure);

                foreach (DataRow dr in dt.Rows)
                {
                    image.ID = Convert.ToInt32(dr["ID"].ToString());
                    image.ImageURL = dr["ImageURL"].ToString();
                    image.IsDefault = Convert.ToBoolean(dr["IsDefault"].ToString());
                    image.ItemID = Convert.ToInt32(dr["ItemID"].ToString());

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return image;
        }

        public bool DeleteImgItem(TblItemImage imgItes)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("sp_TblItemImage_Del",
                    new string[] { "@p_ID" },
                    new object[] { imgItes.ID },
                    CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

    }
}
